﻿<Window x:Class="VisualCode.Forms.MainWin"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:system="clr-namespace:System;assembly=mscorlib"
    xmlns:objectMode="clr-namespace:System.Collections.ObjectModel;assembly=mscorlib"
    xmlns:vcforms="clr-namespace:VisualCode.Forms"
    xmlns:vcclient="clr-namespace:VisualCode.Client;assembly=VisualCode.Client"
    Title="Visual Q" Height="421" Width="616">

    <Window.Resources>



        <x:Array x:Key="ClassMemberCategories" Type="{x:Type vcforms:ClassMemberCategory}">
            <vcforms:ClassMemberCategory Name="Attributes" MemberBinding="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type TreeViewItem}}, Path=DataContext.Fields}" />
            <vcforms:ClassMemberCategory Name="Events" />
            <vcforms:ClassMemberCategory Name="Fields" />
            <vcforms:ClassMemberCategory Name="Methods" MemberBinding="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type TreeViewItem}}, Path=DataContext.Properties}" />
            <vcforms:ClassMemberCategory Name="Properties" />
        </x:Array>
        
        <Style x:Key="{x:Type TreeViewItem}" TargetType="{x:Type TreeViewItem}">
            <Setter Property="IsExpanded" Value="False" />
        </Style>

        <!--<CollectionViewSource x:Key="ClassMemberCategoriesView" Source="{StaticResource ClassMemberCategories}" />-->


        <!--<SolidColorBrush x:Key="GlyphBrush" Color="#444" />


        
        
        <Style x:Key="ExpandCollapseToggleStyle" TargetType="ToggleButton">
            <Setter Property="Focusable" Value="False"/>
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="ToggleButton">
                        <Grid
          Width="15"
          Height="13"
          Background="Transparent">
                            <Path x:Name="ExpandPath"
            HorizontalAlignment="Left" 
            VerticalAlignment="Center" 
            Margin="1,1,1,1"
            Fill="{StaticResource GlyphBrush}"
            Data="M 4 0 L 8 4 L 4 8 Z"/>
                        </Grid>
                        <ControlTemplate.Triggers>
                            <Trigger Property="IsChecked"
               Value="True">
                                <Setter Property="Data"
                TargetName="ExpandPath"
                Value="M 0 4 L 8 4 L 4 8 Z"/>
                            </Trigger>
                        </ControlTemplate.Triggers>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>-->


        <ContextMenu x:Key="ProjectContextMenu">
            <MenuItem Header="New Namespace" />
        </ContextMenu>

        <!-- Namespace Context Menu -->
        <ContextMenu x:Key="NamespaceContextMenu">
            <MenuItem Header="New Class"></MenuItem>
            <MenuItem Header="New Enum"></MenuItem>
            <MenuItem Header="New Struct"></MenuItem>

            <Separator />

            <MenuItem Header="Delete" Command="Delete" >
                <MenuItem.Icon>
                    <Image Width="16" Height="16" Source="/VisualCode.Forms;component/Images/Delete.png" />
                </MenuItem.Icon>
            </MenuItem>
        </ContextMenu>

        <!-- Class Context Menu -->
        <ContextMenu x:Key="ClassContextMenu">
            <MenuItem Header="Delete" Command="Delete" >
                <MenuItem.Icon>
                    <Image Width="16" Height="16" Source="/VisualCode.Forms;component/Images/Delete.png" />
                </MenuItem.Icon>
            </MenuItem>
            <MenuItem Header="Rename">
            </MenuItem>
        </ContextMenu>
        

        <!-- Class Control Template  -->
        <!--<ControlTemplate x:Key="ClassTreeViewItemControlTemplate"  TargetType="{x:Type TreeViewItem}">
            <Grid>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition MinWidth="19"
                      Width="Auto"/>
                    <ColumnDefinition Width="Auto"/>
                    <ColumnDefinition Width="*"/>
                </Grid.ColumnDefinitions>
                <Grid.RowDefinitions>
                    <RowDefinition Height="Auto"/>
                    <RowDefinition/>
                </Grid.RowDefinitions>
                <ToggleButton x:Name="Expander"
                  Style="{StaticResource ExpandCollapseToggleStyle}"
                  IsChecked="{Binding Path=IsExpanded,
                              RelativeSource={RelativeSource TemplatedParent}}"
                  ClickMode="Press"/>
                <Border Name="Bd"
              Grid.Column="1"
              Background="{TemplateBinding Background}"
              BorderBrush="{TemplateBinding BorderBrush}"
              BorderThickness="{TemplateBinding BorderThickness}"
              Padding="{TemplateBinding Padding}">
                    <ContentPresenter x:Name="PART_Header"
                      ContentSource="Header"
                      HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"/>
                </Border>

               

                <ItemsPresenter x:Name="ItemsHost"
                  Grid.Row="1"
                  Grid.Column="1"
                  Grid.ColumnSpan="2">
                    
                    
                    
                    
                </ItemsPresenter>
            </Grid>
            <ControlTemplate.Triggers>
                <Trigger Property="IsExpanded"
               Value="false">
                    <Setter TargetName="ItemsHost"
                Property="Visibility"
                Value="Collapsed"/>
                </Trigger>
                <Trigger Property="HasItems"
               Value="false">
                    <Setter TargetName="Expander"
                Property="Visibility"
                Value="Hidden"/>
                </Trigger>
                <MultiTrigger>
                    <MultiTrigger.Conditions>
                        <Condition Property="HasHeader"
                     Value="false"/>
                        <Condition Property="Width"
                     Value="Auto"/>
                    </MultiTrigger.Conditions>
                    <Setter TargetName="PART_Header"
                Property="MinWidth"
                Value="75"/>
                </MultiTrigger>
                <MultiTrigger>
                    <MultiTrigger.Conditions>
                        <Condition Property="HasHeader"
                     Value="false"/>
                        <Condition Property="Height"
                     Value="Auto"/>
                    </MultiTrigger.Conditions>
                    <Setter TargetName="PART_Header"
                Property="MinHeight"
                Value="19"/>
                </MultiTrigger>
                <Trigger Property="IsSelected"
               Value="true">
                    <Setter TargetName="Bd"
                Property="Background"
                Value="{DynamicResource {x:Static SystemColors.HighlightBrushKey}}"/>
                    <Setter Property="Foreground"
                Value="{DynamicResource {x:Static SystemColors.HighlightTextBrushKey}}"/>
                </Trigger>
                <MultiTrigger>
                    <MultiTrigger.Conditions>
                        <Condition Property="IsSelected"
                     Value="true"/>
                        <Condition Property="IsSelectionActive"
                     Value="false"/>
                    </MultiTrigger.Conditions>
                    <Setter TargetName="Bd"
                Property="Background"
                Value="{DynamicResource {x:Static SystemColors.ControlBrushKey}}"/>
                    <Setter Property="Foreground"
                Value="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}"/>
                </MultiTrigger>
                <Trigger Property="IsEnabled"
               Value="false">
                    <Setter Property="Foreground"
                Value="{DynamicResource {x:Static SystemColors.GrayTextBrushKey}}"/>
                </Trigger>
            </ControlTemplate.Triggers>
        </ControlTemplate>-->
        
        <DataTemplate x:Key="FieldDataTemplate">

            <Grid>
                <Grid.RowDefinitions>
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="Auto" />
                </Grid.RowDefinitions>

                <StackPanel Orientation="Horizontal">
                    <Image Width="16" Height="16" Source="/VisualCode.Forms;component/Images/PublicField.png" />
                    <TextBlock Text="{Binding Name}"  />
                </StackPanel>

            </Grid>

        </DataTemplate>
        
        <!-- ClassMemberCategory Template -->
        <HierarchicalDataTemplate 
            x:Key="ClassMemberCategoryTemplate" 
            ItemTemplate="{StaticResource FieldDataTemplate}"
            ItemsSource="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type TreeViewItem}}, Path=DataContext.MemberBinding}" >
            
            <!--<HierarchicalDataTemplate.ItemsSource>
                <Binding Mode="OneWay" Path="Fields" RelativeSource="{RelativeSource Mode=TemplatedParent}" />
            </HierarchicalDataTemplate.ItemsSource>-->

            <Grid>
                <Grid.RowDefinitions>
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="Auto" />
                </Grid.RowDefinitions>

                <StackPanel Orientation="Horizontal">
                    <Image Width="16" Height="16" Source="/VisualCode.Forms;component/Images/FolderOpen.png" />
                    <TextBlock Text="{Binding Name}"  />
                </StackPanel>

            </Grid>
            
        </HierarchicalDataTemplate>


        <!-- Class Template -->
        <HierarchicalDataTemplate 
            x:Key="ClassTemplate" 
            ItemsSource="{Binding Source={StaticResource ClassMemberCategories}}" 
            ItemTemplate="{StaticResource ClassMemberCategoryTemplate}">
            
            <HierarchicalDataTemplate.ItemContainerStyle>
                <Style TargetType="{x:Type TreeViewItem}">
                    <Setter Property="IsExpanded" Value="False" />
                </Style>
            </HierarchicalDataTemplate.ItemContainerStyle>
            
            <Grid>
                <Grid.RowDefinitions>
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="Auto" />
                </Grid.RowDefinitions>

                <StackPanel Orientation="Horizontal">
                    <Image Source="/VisualCode.Forms;component/Images/PublicClass.png" />
                    <TextBlock Text="{Binding Name}"  />
                </StackPanel>

           </Grid>

        </HierarchicalDataTemplate>

        <!-- Namespace Template -->
        <HierarchicalDataTemplate x:Key="NamespaceTemplate"  ItemsSource="{Binding Types}" ItemTemplate="{StaticResource ClassTemplate}">
            

            <HierarchicalDataTemplate.ItemContainerStyle>
                <Style TargetType="{x:Type TreeViewItem}">
                    <Setter Property="ContextMenu" Value="{StaticResource ClassContextMenu}" />
                    <Setter Property="IsExpanded" Value="True"    />
                    <Setter Property="ToolTip" Value="{Binding Name}" />
                    <Setter Property="IsExpanded" Value="False" />
                    
                </Style>
            </HierarchicalDataTemplate.ItemContainerStyle>

            <StackPanel Orientation="Horizontal">
                <Image Source="/VisualCode.Forms;component/Images/Namespace.png" />
                <TextBlock Text="{Binding Name}"  />
            </StackPanel>

        </HierarchicalDataTemplate>

        <!-- Project Template -->
        <HierarchicalDataTemplate 
            x:Key="ProjectTemplate" 
            ItemsSource="{Binding Namespaces}" 
            ItemTemplate="{StaticResource NamespaceTemplate}">

            <HierarchicalDataTemplate.ItemContainerStyle>
                <Style TargetType="{x:Type TreeViewItem}">
                    <Setter Property="ContextMenu" Value="{StaticResource NamespaceContextMenu}" />

                    <!--<Setter Property="DataContext" Value="{StaticResource ClassChildViewSource}" />-->
                    <!--<Setter Property="Items">
                        <Setter.Value>
                            <x:Array Type="{x:Type TreeViewItem}">
                                <TreeViewItem Header="Attributes"></TreeViewItem>
                                <TreeViewItem Header="Fields" ItemsSource="{Binding Fields}"></TreeViewItem>
                                <TreeViewItem Header="Properties"></TreeViewItem>
                            </x:Array>
                        </Setter.Value>
                    </Setter>-->
                </Style>
            </HierarchicalDataTemplate.ItemContainerStyle>

            <StackPanel Orientation="Horizontal">
                <Image Source="/VisualCode.Forms;component/Images/Assembly.png" />
                <TextBlock Text="{Binding Name}"  />
            </StackPanel>

        </HierarchicalDataTemplate>

    </Window.Resources>

    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto" />
            <RowDefinition Height="80*" />
            <RowDefinition Height="4" />
            <RowDefinition Height="40*" />
        </Grid.RowDefinitions>

        <Menu>
            <MenuItem Header="_File"></MenuItem>
            <MenuItem Header="_Build">
                <MenuItem Header="Build Solution" x:Name="BuildSolution" Click="BuildSolution_Click"></MenuItem>
            </MenuItem>
        </Menu>

        <Grid Grid.Row="1">
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="30*" />
                <ColumnDefinition Width="4" />
                <ColumnDefinition Width="60*" />
            </Grid.ColumnDefinitions>

            <TreeView x:Name="SolutionExplorerTreeView" ItemTemplate="{StaticResource ProjectTemplate}">

            </TreeView>

            <GridSplitter 
                Grid.Column="1" 
                ResizeDirection="Columns" 
                Width="Auto" 
                HorizontalAlignment="Stretch" />

        </Grid>

        <GridSplitter 
            Grid.Row="2" 
            VerticalAlignment="Stretch" 
            Width="Auto" 
            HorizontalAlignment="Stretch" 
            Height="Auto" 
            ResizeDirection="Rows" />

        <TabControl Grid.Row="3">
            <TabItem Header="Output">
                <TextBox x:Name="OutputTextBox" 
                         FontFamily="Courier New" 
                         FontSize="8pt" 
                         TextWrapping="NoWrap" 
                         VerticalScrollBarVisibility="Visible" 
                         HorizontalScrollBarVisibility="Auto">

                </TextBox>
            </TabItem>
        </TabControl>
    </Grid>
</Window>
